package com.information.manage.basic.controller;

import com.information.manage.basic.model.query.AddDictionaryInfoQuery;
import com.information.manage.basic.model.query.MoveDictionaryInfoQuery;
import com.information.manage.basic.model.query.UpdateDictionaryInfoQuery;
import com.information.manage.basic.model.vo.DictionaryInfoListVO;
import com.information.manage.basic.common.result.Result;
import com.information.manage.basic.service.DictionaryInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "字典项信息")
@RestController
@RequestMapping("/dictionary/info")
public class DictionaryInfoController {

    @Resource
    private DictionaryInfoService dictionaryInfoService;

    @PostMapping("/add")
    @ApiOperation(value = "新增字典项", notes = "新增字典项")
    public Result<Integer> addDictionaryInfo(@RequestBody AddDictionaryInfoQuery addDictionaryInfoQuery){
        return dictionaryInfoService.addDictionaryInfo(addDictionaryInfoQuery);
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改字典项", notes = "修改字典项")
    public Result<Boolean> updateDictionaryInfo(@RequestBody UpdateDictionaryInfoQuery updateDictionaryInfoQuery){
        return dictionaryInfoService.updateDictionaryInfo(updateDictionaryInfoQuery);
    }

    @PutMapping("/move")
    @ApiOperation(value = "移动字典项", notes = "移动字典项")
    public Result<Boolean> moveDictionaryInfo(@RequestBody MoveDictionaryInfoQuery moveDictionaryInfoQuery){
        return Result.ok(dictionaryInfoService.moveDictionaryInfo(moveDictionaryInfoQuery.getId(), moveDictionaryInfoQuery.isUp()));
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "删除字典项", notes = "删除字典项")
    public Result<Boolean> deleteDictionaryInfo(@RequestBody List<Integer> ids){
        return dictionaryInfoService.deleteDictionaryInfo(ids);
    }

    @GetMapping("/list/by/category")
    @ApiOperation(value = "根据类型id查询字典项", notes = "根据类型id查询字典项")
    public Result<List<DictionaryInfoListVO>> queryListByCategoryId(Integer categoryId){
        return Result.ok(dictionaryInfoService.queryListByCategoryId(categoryId));
    }

}
